package com.study.rabbitmq.topic;

import com.rabbitmq.client.Channel;
import com.study.rabbitmq.utils.RabbitMqUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class Product {
    private static final String EXCHANGE_NAME = "topic";

    public static void main(String[] args) throws IOException {
        Channel channel = RabbitMqUtil.getChannel();
        Map<String,String> map = new HashMap<>();
        map.put("quick.orange.rabbit"," 被队列Q1Q2接收到");
        map.put("lazy.orange.elephant","被队列Q1Q2接收到");
        map.put("quick.orange.fox","被队列Q1接收到");
        map.put("lazy.brown.fox","被队列Q2接收到");
        map.put("lazy.pink.rabbit","虽然满足两个绑定但只被队列Q2接收一次");
        map.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        map.put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        map.put("lazy.orange.male.rabbit","是四个单词但匹配Q2");
        for (Map.Entry<String,String> bindKeyEntry : map.entrySet()){
            String routingKey = bindKeyEntry.getKey();
            String routingValue = bindKeyEntry.getValue();
            channel.basicPublish(EXCHANGE_NAME,routingKey,null,routingValue.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送的消息："+routingValue);
        }
    }
 }
